package com.cskaoyan.gateway.controller.shopping;


import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
public class ShopIndexController {

    @Reference
    IHomeService iHomeService;
    @Reference
    IContentService iContentService;
    @Reference
    IProductCateService iProductCateService;

    @RequestMapping("/homepage")
    @Anoymous
    public ResponseData homepage() {
        HomePageResponse response = iHomeService.homepage();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @RequestMapping("/navigation")
    @Anoymous
    public ResponseData navigation() {
        NavListResponse response = iContentService.queryNavList();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response.getPannelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


    @RequestMapping("/categories")
    @Anoymous
    public ResponseData categories() {

        AllProductCateResponse response = iProductCateService.getAllProductCate();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }





}
